<template>
  <div class="c-w100">
    <open-modal :openModal="openModal" @closeModal="closeModal">
      <div class="c-bg-white c-pt40 c-br-tl20 c-br-tr20 c-p">
        <div class="c-fc-xblack c-fs28 c-fw-b c-w100 c-pa c-p-t32 c-p-l0 c-textAlign-c c-pz100" @click="goCampDetail()">训练营目录</div>
        <div class="c-ph24 c-flex-row c-justify-sb c-aligni-center c-pb30 c-p c-pz10">
          <div class="c-flex-row c-aligni-center c-fs22 c-fc-xblack">
            <div class="iconfont c-fs16 c-mr12">&#xe600;</div>返回训练营
          </div>
        </div>
        <div id="scrollDir" class="c-pb32 c-maxh600 c-contexty-auto c-ph24">
          <div v-if="!campPermission && !campDetail.isTeacher" class="c-m-0auto c-pb160 c-textAlign-c c-pt140">
            <img class="c-ww210 c-mb30 c-m-0auto" :src="require('@/assets/i/wap/course/noColumnPermission.png')"/>
            <div class="c-fw-b c-fs26 c-fc-xblack c-mb40">暂无权限，购买后查看训练营目录</div>
            <div class="c-fw-b c-fs26 c-fc-white c-bg-FF5D3D c-br32 c-hh64 c-lh64 c-ww360 c-m-0auto" @click="goCampDetail()">前往购买</div>
          </div>
          <div v-else class="">
            <div class="c-pv28" :class="index == dirsList.length - 1 ? '' : 'c-bd-b1-f6'" v-for="(item, index) in dirsList" :key="index">
              <div @click="changeExpandStatus(index)" class="c-flex-row c-justify-sb c-aligni-center c-fs26">
                <div class="c-flex-grow1 c-w0 c-flex-row c-aligni-center c-text-ellipsis1" :class="curPartIndex == index ? 'theme-fc c-fw-b' : ''">
                  <!-- <span class="c-flex-shrink0 iconfont c-fs20 c-mr10 c-fc-gray c-fw400">{{isExpanded && expandedIndex === index ? '&#xe6ab;' : '&#xe6a9;'}}</span> -->
                  <span class="c-flex-shrink0 c-mr10 c-pt2">{{getIndex(index)}}</span>
                  <span class="c-flex-grow1 c-w0 c-text-ellipsis1">{{item.name}}</span>
                </div>
                <div class="c-flex-shrink0">
                  <span class="c-fs20 c-fc-gray">{{getDateFormat(item.date)}}</span>
                  <span v-show="item.lessons.length>0" class="iconfont c-fs18 c-ml10 c-fc-gray">{{isExpanded && expandedIndex === index ? '&#xe6ab;' : '&#xe6a9;'}}</span>
                </div>
              </div>
              <template v-if="isExpanded && expandedIndex == index">
                <div :id="curPartIndex == index && curLessonIndex == lessIndex ? 'curLesson' : ''" class="c-w100 c-flex-row c-justify-sb c-aligni-center" v-for="(lesson, lessIndex) in item.lessons" :key="lessIndex" @click="clickLessonDetail(lesson, dirsList[index].isLock, lessIndex, index)">
                  <div class="c-w100 c-fs24 c-flex-row c-aligni-start" :class="lessIndex == 0 ? 'c-mt28' : ''">
                    <span class="c-flex-shrink0 theme-bd1 c-fs16 c-br8 c-ph10 c-hh32 c-lh32 theme-fc c-mr10 c-ws-n c-flex-row c-flex-center">{{ getTypeName(lesson.relType, lesson.parentType) || ''}}</span>
                    <div class="c-fc-xblack c-flex-grow1 c-flex-column c-text-ellipsis1" :class="lessIndex == (item.lessons.length - 1) ? '' : 'c-pb48'">
                      <span class="c-text-ellipsis1" :class="curPartIndex == index && curLessonIndex == lessIndex ? 'theme-fc' : ''">{{lesson.relName}}</span>
                      <div class="c-flex-row c-aligni-center">
                        <span class="c-fs18 c-ph8 c-pv2 c-lh-n theme-bg-10 c-fc-white c-br4 c-mr8 c-p c-vcAlign-middle c-mr10 c-mt12" v-if="lesson.enableDayPractice==1">
                          <span class="theme-fc c-fs18">每日一练</span>
                          <span class="c-pa prodType-triangle"></span>
                        </span>
                        <div class="c-mt12" v-if="!campDetail.isTeacher && campDetail.isEnroll && !lesson.isLock && lesson.relType == ckfrom.testpPaper && lesson.notReachedButton == true">
                          <div class="c-fs20 c-ph10 theme-fc c-hh24 theme-bg-10 c-flex-row c-flex-center c-br4 c-mr20" @click.stop="handleClickStandard(lesson)">未达标
                            <i class="iconfont c-fs18 c-ml4">&#xe963;</i>
                          </div>
                          <div class="c-fc-gray c-fs18" v-if="!dirsList[index].isLock">已完成{{lesson.ratio}}%</div>
                        </div>
                        <div class="c-fc-gray c-mt12 c-fs18" v-if="!campDetail.isTeacher && campDetail.isEnroll && !lesson.isLock && !dirsList[index].isLock && lesson.ratio != 0 && campDetail.hasPermission">已完成{{lesson.ratio}}%</div>
                      </div>
                    </div>
                    <div class="c-flex-shrink0 c-fs20 c-fc-gray c-ph10" v-if="campDetail.modeType == 4 && lesson.startAt && lesson.endAt">{{lesson.startAt}}~{{lesson.endAt}}</div>
                    <div class="c-flex-shrink0 c-pr14 c-fs16 c-flex-row c-flex-center c-fc-sblack" v-if="isLockIcon(lesson, index)"><span class="iconfont">&#xe7a5;</span></div>
                  </div>
                </div>
              </template>
            </div>
            <loading-status-tem :noData="!isLoading && dirsList.length <= 0" :pt20="true" :imgWidth="'c-ww200'" :noDataText="'暂无相关环节'" :showLoading="isLoading"></loading-status-tem>
            <div v-if="dirsList.length <= 0" class="c-flex-row c-justify-center">
              <span class="c-fc-smblue c-fs28 c-text-decoration-underline" @click="getDirs">刷新</span>
            </div>
          </div>
        </div>
        <div class="c-ph24 c-pv12">
          <div class="c-bd1-ccc c-hh64 c-lh64 c-w100 c-br32 c-textAlign-c c-fs26" @click="closeModal">关闭</div>
        </div>
      </div>
    </open-modal>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js"
import OpenModal from "@/components/templates/common/openModal.vue";
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";

let isLoading = false;
export default {
  name: "campDirectoryDialog",
  components: {
    OpenModal,
    loadingStatusTem
  },
  props: {
  },
  data() {
    return {
      isPrev: false,
      isNext: false,
      listPage: 1,
      dirsList: [],
      openModal: false,
      isExpanded: true, // 是否展开环节
      expandedIndex: 0, // 展开的是哪个环节
      campDetail: {},
      ckfrom: global.ckFrom,
      curPartIndex: 0,
      curLessonIndex: 0,
      isNextUnlock: false, // 下一节是否解锁
      themeId: '',
      isFirstPop: false, // 是否是第一次打开弹窗，防止页面切换时，滚动到当前章节不生效
      campPermission: false,
      campId: '',
      tpId: '',
      tlId: ''
    }
  },
  computed: {
  },
  watch: {},
  mounted() {
    this.openModal = false
  },
  activated() {
    this.openModal = false
  },
  methods: {
    isLockIcon(lesson, index) {
      const modeType = this.campDetail ? this.campDetail.modeType : 0
      const dateLockType = this.campDetail.dateLockType || 1
      const isLessonLock = lesson.isLock && (modeType == 3 || modeType == 4 || (modeType == 1 && dateLockType == 2))
      const isPartLock = this.dirsList && this.dirsList[index] ? this.dirsList[index].isLock : false
      return this.campDetail && this.campDetail.isEnroll && (isLessonLock || isPartLock) && !this.campDetail.isTeacher
    },
    getTypeName(relType, parentType) {
      const relTypeMap = {
        5: '课程',
        8: '资料',
        51: '直播',
        41: '打卡',
        11: '测评',
        75: '互动测评',
        76: '表单',
        77: 'AI测评',
        125: '考试',
        129: '练习',
        142: '电子书',
        780: '课程',
        202: '作业',
      }
      const courseMap = {
        0: '视频',
        1: '音频',
        2: '图文'
      }
      return relType == 5 || relType == 780 ? courseMap[parentType] : relTypeMap[relType]
    },
    changeExpandStatus(index) {
      if (this.expandedIndex == index) {
        this.isExpanded = !this.isExpanded
        return
      }
      this.expandedIndex = index
      this.isExpanded = true
    },
    getDateFormat(date) {
      return utilJs.dateFormatNew(date, "MM月DD日");
    },
    getIndex(index) {
      const num = index + 1
      return num < 9 ? `0${num}` : num
    },
    handleCampDirectory(type) { // type  0查看目录弹窗  -1上一节  1下一节
      if (type == -1) {
        this.goBeforeCampCourse()
      } else if (type == 1) {
        this.goNextCampCourse()
      } else {
        this.popCampList()
      }
    },
    goCampDetail() {
      if (!this.campId || this.campId < 0) {
        return
      }
      this.$routerGo(this, "push", { path: "/homePage/camp/campDetail?campId=" + this.campId });
    },
    closeModal() {
      document.getElementById('scrollDir') && document.getElementById('scrollDir').removeEventListener('scroll', this.scrollFunction);
      this.openModal = false
    },
    //获取目录
    getDirs() {
      if (isLoading) {
        return;
      }
      isLoading = true;
      const curPage = parseInt(this.curPartIndex / 10) + 1
      let limit10 = this.listPage == 1 ? curPage * 10 : 10;
      let postUrl = `${global.apiurl}k12/trainings/${this.campId}/dirs?page=${this.listPage}&limit=${limit10}`;
      utilJs.getMethod(postUrl, res => {
        isLoading = false;
        if (this.listPage == 1) {
          this.dirsList = res.data;
        } else {
          this.dirsList = this.dirsList.concat(res.data);
        }
        if (this.listPage == 1) {
          this.$nextTick(() => {
            const curLessonDom = document.getElementById('curLesson')
            if (curLessonDom) {
              curLessonDom.scrollIntoView({ block: "center", behavior: "smooth" });
            }
          })
        }
        this.listPage = res.data && (res.data.length >= limit10) ? (this.listPage + 1) : this.listPage;
        this.listIsPage = res.data && (res.data.length >= limit10) ? true : false;
        if (this.campDetail.hasPermission && this.listIsPage && this.listPage == 2 && curPage > 1) {
          this.listPage = curPage + 1;
        }
      }, failRes => {
        isLoading = false;
      });
    },
    initData(data) {
      this.isPrev = false
      this.isNext = false
      this.listPage = 1
      this.dirsList = []
      this.isExpanded = true
      this.expandedIndex = 0
      this.campDetail = {}
      this.ckfrom = global.ckFrom
      this.curPartIndex = 0
      this.curLessonIndex = 0
      this.isNextUnlock = false
      this.themeId = ''
      this.isFirstPop = false
      this.campPermission = false
      // 获取到训练营营期、环节、学习任务id，初始化数据
      this.campId = data.ttId
      this.tpId = data.tpId
      this.tlId = data.tlId
      this.isFirstPop = true
      return new Promise((resolve, reject) => {
        let postUrl = `${global.apiurl}common/getProdTrainingPosition/${this.campId}/${this.tpId}/${this.tlId}`;
        utilJs.getMethod(postUrl, res => {
          this.campDetail = res
          if (!(this.campDetail && this.campDetail.payType)) { // 判断接口是否有返回内容
            return
          }
          this.campPermission = this.campDetail && this.campDetail.hasPermission && this.campDetail.isEnroll
          this.isPrev = res.position && res.position.pre ? true : false
          this.isNext = res.position && res.position.next ? true : false
          const prevLesson = res.position.pre || {}
          const nextLesson = res.position.next || {}
          const modeType = this.campDetail.modeType
          const dateLockType = this.campDetail.dateLockType
          const isNextLock = this.campDetail.isEnroll && (((modeType == 3 || modeType == 4) && nextLesson.innerLock) || (nextLesson.outLock))
          const isDateNextLock = this.campDetail.isEnroll && ((modeType == 1 && dateLockType == 2 && nextLesson.innerLock) || nextLesson.outLock )
          const nextLock = modeType == 3 || modeType == 4 ? isNextLock : isDateNextLock

          const isPrevLock = modeType == 1 && dateLockType == 2 ? prevLesson.innerLock : false;// 如果不是日期+自定义时间 其他上一节默认解锁
          const prevLock = this.campDetail.isEnroll && isPrevLock
          this.isPrevUnlock = !prevLock
          this.isNextUnlock = !this.isNext || nextLock ? false : true
          const curLesson = res.position.cur || {}
          this.curPartIndex = curLesson.outIndex || 0;
          this.curLessonIndex = curLesson.innerIndex || 0;
          this.expandedIndex = curLesson.outIndex || 0;
          let campButtonStatus = { // 当前课程是否有上下节
            isPrev: this.isPrev,
            isNext: this.isNext,
            isNextUnlock: this.isNextUnlock,
            isTeacher: this.campDetail.isTeacher,
            campPermission: this.campPermission,
            modeType: this.campDetail.modeType,
            isPrevUnlock: this.isPrevUnlock,
            curLessonRatio: curLesson.data && curLesson.data.ratio ? curLesson.data.ratio : 0
          }
          if (this.campDetail.modeType == 1) {
            campButtonStatus = {
              ...campButtonStatus,
              dateLockType
            }
          }
          resolve(campButtonStatus);
        }, failRes => {
          reject(failRes)
        });
      })
    },
    popCampList() {
      if (!this.campId) {
        return
      }
      this.openModal = true;
      // 没有目录的时候请求，有的话就不请求，减少消耗，如果要更新目录，可能就要自己刷新页面
      if (!(this.dirsList && this.dirsList.length)) {
        this.listPage = 1;
        this.getDirs()
        this.$nextTick(() => {
          const scrollDirDom = document.getElementById('scrollDir')
          if (scrollDirDom) {
            // 到详情页时，第一次打开弹窗需要将弹窗滚动到顶部，防止页面切换返回等操作，导致弹窗打开自动滚动到当前章节的操作失效
            this.isFirstPop && scrollDirDom.scrollTo(0, 0);
            scrollDirDom.addEventListener('scroll', this.scrollFunction);
            this.isFirstPop = false
          }
        })
      }
    },
    scrollFunction() {
      const scrollDirDom = document.getElementById('scrollDir');
      if (!scrollDirDom) {
        return
      }
      const scrollTop = scrollDirDom.scrollTop || 0;
      const clientHeight = scrollDirDom.clientHeight || 0;
      const scrollHeight = scrollDirDom.scrollHeight || 0;
      if (scrollTop + clientHeight >= (scrollHeight - 20) && this.listIsPage) {
        this.getDirs()
      }
    },
    goBeforeCampCourse() {
      const position = this.campDetail.position || {}
      const lesson = position.pre
      if (!this.isPrev || !lesson) {
        return
      }
      const isLock = this.campDetail.isTeacher ? false : position.pre ? position.pre.outLock : false
      lesson.data.isLock = position.pre ? position.pre.innerLock : false
      this.clickLessonDetail(lesson.data, isLock, lesson.innerIndex, lesson.outIndex)
    },
    goNextCampCourse() {
      const position = this.campDetail.position || {}
      const lesson = position.next
      if (!this.isNext || !lesson) {
        return
      }
      const isLock = this.campDetail.isTeacher ? false : position.next ? position.next.outLock : false
      lesson.data.isLock = position.next ? position.next.innerLock : false
      this.clickLessonDetail(lesson.data, isLock, lesson.innerIndex, lesson.outIndex)
    },
    // 记录上次学习位置
    setCampProgress(lessIndex, index) {
      let data = {
        prodId: this.campId,
        prodType: global.ckFrom.camp,
        innerIndex: lessIndex,
        outIndex: index,
        // 新增tlId，防止后台移动学习任务或学习环节，上次学习位置对不上，获取训练营详情接口会根据tlId，重新匹配tlId在目录的位置
        tlId: this.dirsList[index] && this.dirsList[index].lessons && this.dirsList[index].lessons[lessIndex] ? this.dirsList[index].lessons[lessIndex].id : '',
        page: Math.floor(index / 10) + 1
      };
      let postUrl = `${global.apiurl}analysis/course/positionLog`;
      utilJs.postMethod(postUrl, data, res => { });
    },
    // entryRecord(lessonInfo, tpId) {
    //   console.log('lessonInfo, tpId', lessonInfo.examStatus, lessonInfo, tpId)
    //   utilJs.postMethod(global.apiurl + "paper/entryRecord", {
    //     paperMainId: lessonInfo.relId,
    //     prodId: this.campId,
    //     prodType: global.ckFrom.camp
    //   }, res => {
    //     if (lessonInfo.examStatus == 0) {
    //       if (lessonInfo.parentType == 1) {
    //         utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + lessonInfo.relId, (res) => {
    //           if (res.status == 1) {
    //             utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
    //               paperMainId: lessonInfo.relId,
    //               topicId:lessonInfo.parentId,
    //               entryProdType:3,
    //               prodId:this.campId
    //             }, res => {
    //               this.$routerGo(this, "push", {
    //                 path: `/homePage/examination/examinationAnswer?paperMainId=${lessonInfo.relId}&topicId=${lessonInfo.parentId}&goOnNum=1&tlId=${lessonInfo.id}&ttId=${this.campId}&tpId=${tpId}&ckFrom=${global.ckFrom.camp}&isRelevance=1&themeId=${this.themeId}`
    //               });
    //             })
    //           } else {
    //             this.$showCjToast({
    //               text: res.msg + '</br>' + res.showTime,
    //               type: 'warn'
    //             });
    //           }
    //         })
    //       }
    //     } else if (lessonInfo.examStatus == 1) {
    //       this.$routerGo(this, "push", {
    //         path: `/homePage/examination/examinationResult?paperMainId=${lessonInfo.relId}&topicId=${lessonInfo.parentId}&tlId=${lessonInfo.id}&ttId=${this.campId}&tpId=${tpId}&ckFrom=${global.ckFrom.camp}&isRelevance=1&themeId=${this.themeId}`
    //       });
    //     } else if (lessonInfo.examStatus == 2) {
    //       utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + lessonInfo.relId, (res) => {
    //         if (res.status == 1) {
    //           this.$routerGo(this, "push", {
    //             path: `/homePage/examination/examinationAnswer?paperMainId=${lessonInfo.relId}&topicId=${lessonInfo.parentId}&goOnNum=${lessonInfo.goOnNum}&tlId=${lessonInfo.id}&ttId=${this.campId}&tpId=${tpId}&ckFrom=${global.ckFrom.camp}&isRelevance=1&themeId=${this.themeId}`
    //           });
    //         } else {
    //           this.$showCjToast({
    //             text: res.msg + '</br>' + res.showTime,
    //             type: 'warn'
    //           });
    //         }
    //       })
    //     }
    //   })
    // },
    // 跳转详情页
    clickLessonDetail: function (lessonInfo, isLock, lessIndex, index) {
      const tpId = lessonInfo ? lessonInfo.tpId : '';
      if (this.campDetail.modeType == 1 && this.campDetail.dateLockType == 2) {
        isLock = lessonInfo.isLock;
      }
      // 当为闯关模式的时候判断更改当前isLock
      if (this.campDetail.modeType == 3) {
        isLock = lessonInfo.isLock;
      }
      // 当为定期模式的时候判断更改当前isLock
      if (this.campDetail.modeType == 4) {
        isLock = lessonInfo.isLock;
      }
      if (this.campDetail.isTeacher) {
        if (this.campDetail.modeType == 1) {
          isLock = lessonInfo.isLock;
        } else {
          isLock = false
        }
      }
      if (isLock && lessonInfo.isFree == 0 || isLock && lessonInfo.isFree == 1 && this.campDetail.hasPermission) {
        this.$showCjToast({
          text: '内容未解锁',
          type: 'warn'
        });
      } else {
        this.setCampProgress(lessIndex, index)
        switch (lessonInfo.relType) {
          // 5课程，8资料，51直播，41打卡，11考试，76表单，77AI测评, 780为新版跳转到视音频课程链接
          case 780:
            this.$routerGo(this, "push", {
              path: `/homePage/camp/campCourse?lessonId=${lessonInfo.id}&themeId=${this.themeId}&relType=${lessonInfo.relType}&campId=${this.campId}&tpId=${tpId}&parentType=${lessonInfo.parentType}&ckFrom=${global.ckFrom.camp}&progress=${lessonInfo.ratio || ''}`
            });
            break
          case 5:
            if (lessonInfo.isCourse == 1) {
              this.$routerGo(this, "push", {
                path: `/homePage/course/${lessonInfo.parentType == 0 ? 'video' : lessonInfo.parentType == 1 ? 'voice' : 'imgText'}?courseId=${lessonInfo.relId}&ckFrom=${global.ckFrom.camp}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&themeId=${this.themeId}`
              })
            } else {
              this.$routerGo(this, "push", {
                path: `/homePage/camp/campCourse?lessonId=${lessonInfo.id}&campId=${this.campId}&tpId=${tpId}&parentType=${lessonInfo.parentType}&ckFrom=${global.ckFrom.camp}&progress=${lessonInfo.ratio}&themeId=${this.themeId}`
              });
            }
            break;
          case 8:
            this.$routerGo(this, "push", {
              path: `/homePage/datum/datumDetail?ttId=${this.campId}&tpId=${tpId}&datumId=${lessonInfo.relId}&ckFrom=${global.ckFrom.camp}&tlId=${lessonInfo.id}&themeId=${this.themeId}`
            });
            break;
          case 51:
            this.$routerGo(this, "push", {
              path: `/homePage/live/liveDetail?liveId=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
            });
            break;
          case 202:
              this.$routerGo(this, "push", {
                path: `/homePage/schoolAssignment/assignDetail?homeworkType=${lessonInfo.homeworkType}&thwId=${lessonInfo.relId}&tlId=${lessonInfo.id}&relType=${lessonInfo.relType}&ttId=${this.campId}&tpId=${tpId}&ckFrom=${global.ckFrom.camp}`
              });
            break;
          case 41:
            switch (lessonInfo.parentType) {
              case 1:
                //日历打卡,若当前日期不在开始日期和结束日期之间，则从开始日期进入，否则从当前日期进入
                let startTimeTamp = new Date(`${lessonInfo.startTime} ${lessonInfo.startHour}`.replace(/-/g, "/")).getTime();
                let endTimeTamp = new Date(`${lessonInfo.endTime} ${lessonInfo.endHour}`.replace(/-/g, "/")).getTime();
                let nowTimeTamp = new Date().getTime();
                let curTime = lessonInfo.startDay; //utilJs.dateFormat(nowTimeTamp);
                if (nowTimeTamp < startTimeTamp || nowTimeTamp > endTimeTamp) {
                  curTime = lessonInfo.startTime;
                }
                // 区分跳转打卡结果页还是任务页面--/进度100%跳转结果页
                if (lessonInfo.ratio == 100) {
                    this.goToTypeClockIn(lessonInfo.parentType, lessonInfo, isLock, tpId, lessIndex, index)
                  } else {
                    this.$routerGo(this, "push", {
                      path: `/homePage/clockIn/stuHomeWorkDiary?workType=1&clockInId=${lessonInfo.parentId}&curDate=${curTime}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
                    });
                  }
                break;
              case 2:
                  // 区分跳转打卡结果页还是任务页面--/进度100%跳转结果页
                  if (lessonInfo.ratio == 100) {
                    this.goToTypeClockIn(lessonInfo.parentType, lessonInfo, isLock, tpId, lessIndex, index)
                  } else {
                    //作业打卡，如果超过一个作业，则进入作业列表，否则进入作业详情
                    this.$routerGo(this, "push", {
                      path: `/homePage/clockIn/stuHomeWorkDiary?workType=2&curId=${lessonInfo.hwId}&clockInId=${lessonInfo.parentId}&fromDetail=&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
                    });
                  }
                break;
              case 3:
                 // 区分跳转打卡结果页还是任务页面--/进度100%跳转结果页
                 if (lessonInfo.ratio == 100) {
                    this.goToTypeClockIn(lessonInfo.parentType, lessonInfo, isLock, tpId, lessIndex, index)
                  } else {
                    //闯关打卡
                    this.$routerGo(this, "push", {
                      path: `/homePage/clockIn/stuHomeWorkDiary?workType=3&clockInId=${lessonInfo.parentId}&curId=${lessonInfo.hwId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${global.ckFrom.camp}&isTraining=1&themeId=${this.themeId}`
                    });
                  }
                break;
            }
            break;
          // case 11:
          //   if (lessonInfo.totalNum == 0) {
          //       this.$showCjToast({
          //         text: '该试卷无题目',
          //         type: 'warn'
          //       });
          //       return
          //   }
          //   this.entryRecord(lessonInfo, tpId)
          //   break;
          case 76:
            this.$routerGo(this, "push", {
              path: `/homePage/form?relId=${lessonInfo.relId}&relType=6&type=2&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${global.ckFrom.camp}&joinType=${this.campDetail.payType}&themeId=${this.themeId}`
            });
            break;
          case 77:
            this.$routerGo(this, "push", {
              path: `/homePage/voiceTest/voiceTestDetail?paperMainId=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&progress=${lessonInfo.ratio}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
            })
            break;
          case 75:
            this.$routerGo(this, "push", {
              path: `/homePage/mutuaTest/mutuaTestDetail?mutuaTestId=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&progress=${lessonInfo.ratio}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
            })
            break;
          case 129:
            this.$routerGo(this, "push", {
              path: `/homePage/itemBank/questionSaleDetail?libraryId=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&progress=${lessonInfo.ratio}&ckFrom=${global.ckFrom.camp}&themeId=${this.themeId}`
            })
            break;
          case 125:
          case 11:
            this.$routerGo(this, "push", {
              path: `/homePage/testPaper/testDetail?testId=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&progress=${lessonInfo.ratio}&ckFrom=${global.ckFrom.camp}&origin=${global.ckFrom.camp}&prodId=${this.campId}&themeId=${this.themeId}`
            })
            break;
          case 142:
            this.$routerGo(this, "push", {
              path: `/homePage/ebooks/ebooksDetail?id=${lessonInfo.relId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&progress=${lessonInfo.ratio}&themeId=${this.themeId}`
            })
        }
        this.closeModal()
      }
    },
    // 跳转打卡不同的
    goToTypeClockIn(workType, lessonInfo, isLock, tpId, lessIndex, index) {
      // 先请求详情接口数据，在分类判断跳转那个接口
      let postUrl = global.apiurl + `signCard/examInfoFromHwId/${lessonInfo.hwId}`
      utilJs.getMethod(postUrl,
        (res) => {
          if (!res.data) {
            // 如果记录被删除，跳转原来的流程
            if (workType == 1) {
              let nowTimeTamp = new Date().getTime();
              let curTime = utilJs.dateFormat(nowTimeTamp);
              this.$routerGo(this, "push", {
                path: `/homePage/clockIn/stuHomeWorkDiary?workType=1&clockInId=${lessonInfo.parentId}&curDate=${curTime}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${this.ckFrom}&themeId=${this.themeId}`
              });
            } else if (workType == 2) {
              //作业打卡，如果超过一个作业，则进入作业列表，否则进入作业详情
              this.$routerGo(this, "push", {
                path: `/homePage/clockIn/stuHomeWorkDiary?workType=2&curId=${lessonInfo.hwId}&clockInId=${lessonInfo.parentId}&fromDetail=&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${this.ckFrom}&themeId=${this.themeId}`
              });
            } else {
              this.$routerGo(this, "push", {
                path: `/homePage/clockIn/stuHomeWorkDiary?workType=3&clockInId=${lessonInfo.parentId}&curId=${lessonInfo.hwId}&ttId=${this.campId}&tpId=${tpId}&tlId=${lessonInfo.id}&ckFrom=${this.ckFrom}&isTraining=1&themeId=${this.themeId}`
              });
            }
          } else {
            // 有返回数据跳转到对应结果页面
            const {examMainId, hwId, signColId, type, startDay} = res.data
            if (type == 1 || type == 4) {
              // 简答题1 表单4
              this.$routerGo(this, "push", {
                path: "/homePage/clockIn/shortAnswerResult",
                query: {
                  clockInId: signColId,
                  curHwId : hwId,
                  curSelectDate: startDay,
                  ttId: this.campId,
                  tpId: tpId,
                  tlId: lessonInfo.id,
                  ckFrom: this.ckFrom,
                  isTraining: 1,
                  workType: workType,
                  examMainId: examMainId,
                }
              });
            } else if (type == 3) {
              // ai语音结果页 type = 3
              this.$routerGo(this, "push", {
                path: "/homePage/clockIn/voiceResult",
                query: {
                  ttId: this.campId,
                  tpId: tpId,
                  tlId: lessonInfo.id,
                  curHwId: hwId,
                  totalNum: lessonInfo.hasQuestions,
                  examMainId: examMainId,
                  clockInId: signColId,
                  workType: workType,
                  curSelectDate: startDay,
                }
              });
            } else {
              // 非简答题2
              this.$routerGo(this, "push", {
                path: "/homePage/clockIn/homeWorkResult",
                query: {
                  ttId: this.campId,
                  tpId: tpId,
                  tlId: lessonInfo.id,
                  examMainId: examMainId,
                  isFromDetail: true,
                  workType: workType,
                  clockInId: signColId,
                  curHwId : hwId,
                  curSelectDate: startDay,
                }
              });
            }
          }
        })
    },
  },
  destroyed() {
  },
};
</script>

<style scoped lang="less">
/deep/ .modal {
  z-index: 10000 !important;
}
</style>

